﻿<%@ Page Title="" Language="C#" MasterPageFile="~/App_form/Menu/dao_tao.master" AutoEventWireup="true" CodeFile="tkb.aspx.cs" Inherits="App_form_Daotao_tkb" %>

<%@ Register TagPrefix="Control" TagName="menu_phai" Src="~/App_ctr/Admin/menu_phai.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div style="width: 100%">
        <div style="width: 20%; float: left;">
            <Control:menu_phai runat="server" ID="menuphai" />
        </div>
        <div style="width: 79.4%; float: right;">
            <div style="background-image: url(../../CSS/images/ui-bg_glass_75_e6e6e6_1x400.png); font-weight: bold; height: 30px; border: 1px solid #d3d3d3; margin-top: 4px; text-align: center; padding-top: 8px; text-transform: uppercase;">
                Thông tin thời khóa biểu
            </div>
            <div style="margin-top: 2px;">
                <div style="display: table; margin: 0 auto; width: 100%; border: 1px solid #d3d3d3; font-size: 16px;">
                    <div id="ndung_ct" class="clearfix">
                        <div style="width: 100%; float: left; padding: 30px;">
                            <div style="float: left; width: 7%;">
                                <label>
                                    Năm học  :
                                </label>
                            </div>
                            <div style="float: left; width: 17%">
                                <Lib:drop runat="server" ID="namhoc" DataTextField="TEN" DataValueField="MA" Width="159px" Height="20px"
                                    onClientChange=" P_PC_LOP_GIANGDAY_LKE()">
                                </Lib:drop>
                            </div>
                            <div style="float: left; width: 6%;">
                                <label>
                                    Học kỳ :
                                </label>
                            </div>
                            <div style="float: left; width: 16%">
                                <Lib:drop runat="server" ID="hocky" DataTextField="TEN" DataValueField="MA" Width="143px" Height="23px" onClientChange=" P_PC_LOP_GIANGDAY_LKE()"></Lib:drop>
                            </div>
                            <div style="float: left; width: 5%;">
                                <label>
                                    Lớp :
                                </label>
                            </div>
                            <div style="float: left; width: 16%">
                                <Lib:drop runat="server" ID="lop" DataTextField="TEN" DataValueField="ID" Width="160px" Height="23px" onClientChange=" P_PC_GIANGDAY_LKE()"></Lib:drop>
                            </div>
                            <div style="width: 100%; height: 6px; float: left;"></div>
                            <div style="float: left; width: 80%">
                                <Lib:Button runat="server" ID="add" Icon="ADD" Text="Thêm mới" Width="100px" onClientClick="P_TKB_NH()"></Lib:Button>
                                <Lib:Button runat="server" ID="del" Icon="DEL" Text="Xóa" Width="100px" onClientClick="P_TKB_XOA()"></Lib:Button>
                            </div>
                        </div>
                        <div style="width: 100%; float: left;">
                            <Lib:gridView runat="server" ID="tkb" Width="1020" Height="400" onClientBeforEdit="tkb_ClientBeforEdit" onClientUpdateCell="tkb_client_UpdateCell">
                                <Columns>
                                    <Lib:Column BaseColumn="thu" Name="Thứ" Width="100" EditControlType="Drop" />
                                    <Lib:Column BaseColumn="giangvien" Name="Giảng viên" Width="300" EditControlType="Drop" />
                                    <Lib:Column BaseColumn="mon" Name="Môn" Width="200" EditControlType="Drop" />
                                    <Lib:Column BaseColumn="giangduong" Name="Giảng đường" Width="300" EditControlType="Drop" />
                                    <Lib:Column BaseColumn="tgian" Name="Thời gian" Width="100" EditControlType="TextBox" />
                                </Columns>
                                <Pager>
                                    <Lib:Pager PageSize="30" />
                                </Pager>
                            </Lib:gridView>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <asp:HiddenField ID="kthuoc" runat="server" Value="0,0" />
    <asp:HiddenField ID="giangduong" runat="server" Value="" />
    <script>
        var data_gv = [], mon = [], giang_duong = [];

        function tkb_ClientBeforEdit(row, cell, val, column) {
            if (column.field == "THU") {
                var a_data = [{ "MA": "T2", "TEN": "Thứ hai" }, { "MA": "T3", "TEN": "Thứ ba" }, { "MA": "T4", "TEN": "Thứ tư" },
                { "MA": "T5", "TEN": "Thứ năm" }, { "MA": "T6", "TEN": "Thứ sáu" }, { "MA": "T7", "TEN": "Thứ bảy" }, { "MA": "CN", "TEN": "Chủ nhật" }];
                column.source = a_data;
            }
            else if (column.field == "GIANGVIEN") {
                column.source = data_gv;
            }
            else if (column.field == "MON") {
                column.source = mon;
            }
            else if (column.field == "GIANGDUONG") {
                var json = $("#<%=giangduong.ClientID%>").val();
                column.source = Common.stringToJson(json);
            }
}
function tkb_client_UpdateCell(row, cell, val) {
    if (cell == 1) {
        b_hk = $("#<%=hocky.ClientID%>").val(), b_nam = $("#<%=namhoc.ClientID%>").val(), b_lop = $("#<%=lop.ClientID%>").val();
        var grid = GetGridByID("<%=tkb.ClientID%>");
        var data = grid.getValueActive();
        var b_ns_id = data.ID_GIANGVIEN;
        wdt_ma.FDT_GIANGVIEN_LKE_MON(b_lop, b_ns_id, b_nam, b_hk, P_TKB_LKE_MON_KQ, ErrorDb, ErrorTimeOut);
    }
}
function P_TKB_LKE_MON_KQ(b_kq) {
    if (CheckError(b_kq)) {
        ShowError(b_kq);
        return;
    }
    mon = Common.stringToJson(b_kq);;
}
//

function P_LOP_LKE_KQ(b_kq) {
    if (CheckError(b_kq)) {
        ShowError(b_kq);
        return;
    }
    var grid = GetDropByID("<%=lop.ClientID%>");
    grid.dataBin(b_kq);
    P_PC_GIANGDAY_LKE();
    return false;
}

function P_PC_LOP_GIANGDAY_LKE() {
    try {
        var b_nam = $("#<%=namhoc.ClientID%>").val();
        var b_hk = $("#<%=hocky.ClientID%>").val();
        wdt_ma.FDT_LOP_PC_LKE(b_nam, b_hk, P_PC_LOP_GIANGDAY_KQ, ErrorDb, ErrorTimeOut);
    }
    catch (err) {
        ShowError(err);
    }
}
function P_PC_LOP_GIANGDAY_KQ(b_kq) {
    if (CheckError(b_kq)) {
        ShowError(b_kq);
        return;
    }

    GetDropByID("<%=lop.ClientID%>").dataBin(b_kq);
    P_PC_GIANGDAY_LKE();
}
function P_PC_GIANGDAY_LKE() {
    try {
        b_hk = $("#<%=hocky.ClientID%>").val(), b_nam = $("#<%=namhoc.ClientID%>").val(), b_lop = $("#<%=lop.ClientID%>").val();
        wdt_ma.FDT_GIANGVIEN_PC_LKE(b_hk, b_nam, b_lop, P_PC_GIANGDAY_KQ, ErrorDb, ErrorTimeOut);
    }
    catch (err) {
        ShowError(err);
    }
}

function P_PC_GIANGDAY_KQ(b_kq) {
    if (CheckError(b_kq)) {
        ShowError(b_kq);
        return;
    }
    data_gv = Common.stringToJson(b_kq);
    P_TKB_TIM();
}

//TIM
function P_TKB_TIM() {
    try {
        b_hk = $("#<%=hocky.ClientID%>").val(), b_nam = $("#<%=namhoc.ClientID%>").val(), b_lop = $("#<%=lop.ClientID%>").val();

        wdt_ma.FDT_TKB_LKE(b_hk, b_nam, b_lop, P_TKB_LKE_KQ, ErrorDb, ErrorTimeOut);
        return false;
    }
    catch (err) {
        ShowError(err);
    }
}

function P_TKB_LKE_KQ(b_kq) {
    if (CheckError(b_kq)) {
        ShowError(b_kq);
        return;
    }
    var grid = GetGridByID("<%=tkb.ClientID%>");
            grid.dataBin(b_kq);
        }

        //NHAP
        function P_TKB_NH() {
            try {
                b_hk = $("#<%=hocky.ClientID%>").val(), b_nam = $("#<%=namhoc.ClientID%>").val(), b_lop = $("#<%=lop.ClientID%>").val();
        var grid = GetGridByID("<%=tkb.ClientID%>");
        var data = grid.getValueByCondition(["THU"], [""], ["!="]);
        var thu = [], ns_id = [], mon = [], gd_id = [], tg_hoc = [];
        $.each(data, function (index, val) {
            thu[index] = val.THU; ns_id[index] = val.ID_GIANGVIEN; mon[index] = val.ID_MON; gd_id[index] = val.ID_GIANGDUONG;
            tg_hoc[index] = val.TGIAN;
        });
        wdt_ma.FDT_TKB_NH(thu, b_lop, ns_id, b_nam, b_hk, mon, gd_id, tg_hoc, P_TKB_NH_KQ, ErrorDb, ErrorTimeOut);
        return false;
    }
    catch (err) {
        ShowError(err);
    }
}

function P_TKB_NH_KQ(b_kq) {
    if (CheckError(b_kq)) {
        ShowError(b_kq);
        return;
    }
    Msg.Show("Cảnh báo", "Nhập thành công", "info");
}

//XOA
function P_TKB_XOA() {
    try {
        b_hk = $("#<%=hocky.ClientID%>").val(), b_nam = $("#<%=namhoc.ClientID%>").val(), b_lop = $("#<%=lop.ClientID%>").val();
        var b_ns_id = "", b_mon = "", b_gd = "", thu = "";
        var grid = GetGridByID("<%=tkb.ClientID%>");
        var data = grid.getValueActive();
        if (data == "" && data == undefined) {
            Msg.Show("cảnh báo", "Chưa chọn dòng để xóa", "error");
            return;
        }
        b_ns_id = data.ID_GIANGVIEN; b_mon = data.ID_MON; b_gd = data.ID_GIANGDUONG;
        thu = data.THU;

        wdt_ma.FDT_TKB_XOA(thu, b_lop, b_ns_id, b_nam, b_hk, b_mon, b_gd, P_TKB_LKE_KQ, ErrorDb, ErrorTimeOut);
        return false;
    }
    catch (err) {
        ShowError(err);
    }
}

function P_TKB_DKY_HOC_KQ(b_kq) {
    if (CheckError(b_kq)) {
        ShowError(b_kq);
        return;
    }
    Msg.Show("Thông báo", "Thành Công", "info");
}
    </script>
</asp:Content>

